﻿''' <summary>
''' 字符串处理函数
''' </summary>
''' <remarks></remarks>
Public Module StringHandle
    ''' <summary>
    ''' 是否打开文件
    ''' </summary>
    ''' <remarks></remarks>
    Public L_openFile As Integer = 0
    Public m_default As Boolean
    Public m_openFile As Integer = 0
    Public m_boolTaxis As Boolean = False
    Public m_start As DateTime
    Public m_end As DateTime
    Public Function GetStringNumber(ByVal str As String) As Integer
        str = " " & str & " " '在字符串前后各加一个空，以便于后面处理
        Dim n As Integer = 0
        Dim n1 As Integer = 0
        Dim n2 As Integer = 0
        If str IsNot Nothing AndAlso str.Length > 2 Then
            While n2 >= 0
                n1 = n2
                n2 = str.IndexOf(" ", n1 + 1)
                If n2 - n1 > 1 Then '如果不是连续的空格，开始计数
                    n = n + 1
                End If
            End While
        End If
        Return n
    End Function
    ''' <summary>
    ''' 取得给定位置的字符串，索引从1开始
    ''' </summary>
    ''' <param name="str">字符串</param>
    ''' <param name="index">位置</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetString(ByVal str As String, ByVal index As Integer) As String
        str = "  " & str & "  " '前后各增加两个空格，以便于正确处理
        Dim substring As String = ""
        Dim n As Integer = 0
        Dim n1 As Integer = 0
        Dim n2 As Integer = 0
        Try
            For i As Integer = 0 To str.Length - 1
                If str.Substring(i, 1) <> " " Then
                    n1 = i
                    n2 = str.IndexOf(" ", n1)
                    substring = str.Substring(n1, n2 - n1)
                    i = n2
                    n = n + 1
                    If n = index Then
                        Return substring
                        Exit Function
                    End If
                End If
            Next
            Return Nothing
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    ''' <summary>
    ''' 经纬度选择 (True)
    ''' </summary>
    ''' <param name="str"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetLastlyChar(ByVal str As String) As Boolean

        Dim empty As String = ""
        Dim w1 As String = "W"
        Dim w2 As String = "w"
        Dim n1 As String = "N"
        Dim n2 As String = "n"
        Dim e1 As String = "E"
        Dim e2 As String = "e"
        Dim s1 As String = "S"
        Dim s2 As String = "s"
        If str.EndsWith(w1) = True Or str.EndsWith(w2) = True Or str.EndsWith(e1) = True Or str.EndsWith(e2) = True Then

            Return True
        ElseIf str.EndsWith(n1) = True Or str.EndsWith(n2) = True Or str.EndsWith(s1) = True Or str.EndsWith(s2) = True Then
            Return False
        Else
            ' Return empty

        End If

    End Function
    ''' <summary>
    ''' 选择文件类型
    ''' </summary>
    ''' <param name="str"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function FileType(ByVal str As String) As Integer
        Dim terra As String = "UA_ID:"


        Dim localeTitle As String = "*% ONSITE"
        Dim reconnaissanceTitle As String = "*% UPPERAIR"
        'Dim localeViscera As String = "*** EOH: END OF ON-SITE QA HEADERS"
        'Dim reconnaissanceViscera As String = "*** EOH: END OF UPPERAIR QA HEADERS"
        If str.Contains("*%") And str.Contains("ONSITE") Then

            Return 2
        ElseIf str.Contains("*%") And str.Contains("UPPERAIR") Then

            Return 3
        Else
            Return 4
        End If
    End Function

End Module

